<template>
    <div class="order">
        <h1>这是订单内容</h1>
        <el-button type="primary" plain @click="select">查询</el-button>
        <el-table
            :data="tableData"
            style="width: 100%"
            ref="filterTable"
            >
            <el-table-column
                fixed
                prop="cso_data"
                label="订单日期"
                width="150"
                >
            </el-table-column>
            <el-table-column
                prop="cso_name"
                label="姓名"
                width="120"
                column-key="name"
                :filters="[{text: '李四', value: '李四'}, {text: '张三', value: '张三'}, {text: '丁伟', value: '丁伟'}, {text: '林当', value: '林当'},{text: '王五', value: '王五'}]"
                :filter-method="filterHandler">
            </el-table-column> 
            <el-table-column
                prop="cso_shop"
                label="购买商品"
                width="120">
            </el-table-column>
            <el-table-column
                prop="cso_receive"
                label="收货地址"
                width="280"
                >
            </el-table-column>
            <el-table-column
                prop="cso_phone"
                label="手机号"
                width="120">
            </el-table-column>
            <el-table-column
                fixed="right"
                label="操作"
                width="120">
            <template slot-scope="scope">
                <el-button
                @click.native.prevent="deleteRow(scope.$index, tableData)"
                type="text"
                size="small">
                删除订单
                </el-button>
            </template>
            </el-table-column>
        </el-table>
    </div>
</template>



<script>
export default {
  methods: {
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    resetDateFilter() {
      this.$refs.filterTable.clearFilter("name");
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    filterHandler(value, row, column) {
      const property = column["property"];
      return row[property] === value;
    },
    select() {
      if (sessionStorage.getItem("isalogin")) {
        this.axios.get("/zqorder").then(result => {
          var result = result.data.result;
          console.log(result);
          for (var i = 0; i < result.length; i++) {
            var data = result[i].cso_data;
            // console.log(data);
            var y = 1627096409809 / (365 * 24 * 60 * 60 * 1000);
            y = Math.floor(y) + 1970;
            console.log(y);
            var m1 = 1627096409809 % (365 * 24 * 60 * 60 * 1000);
            var m2 = m1 / 1000 / 60 / 60 / 24 / 30;
            var m = Math.floor(m2);
            console.log(m);
            var d = m2 % (1000 * 60 * 60 * 24);
            d = Math.floor(d);
            console.log(d);
            result[i].cso_data = y + "-" + m + "-" + d;
            console.log(result);
          }
          this.tableData = result;
        });
      }else{
          this.$message.error('请先登录哦！');
      }
    }
  },
  data() {
    return {
      tableData: [] //存储订单信息
    };
  }
};
</script>